<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css">
    <script type="text/javascript" src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
    <title>position</title>
    <style>
        html,
        body {
            margin: 0;
            height: 100%;
            width: 100%;
            position: absolute;
        }

        #container {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            width: 100%;
            height: 100%;
        }

        .custom-input-card .btn:last-child {
            margin-left: 1rem;
        }

        .content-window-card {
            position: relative;
            width: 23rem;
            padding: 0.75rem 0 0 1.25rem;
            box-shadow: none;
            bottom: 0;
            left: 0;
        }

            .content-window-card p {
                height: 2rem;
            }
    </style>
</head>
<body>
    <div id="container" class="map"></div>
    <div class="input-card">
        <h4>左击获取经纬度：</h4>
        <div class="input-item">
            <input type="text" readonly="true" id="lnglat">
        </div>
    </div>

    <!-- 加载地图JSAPI脚本 -->
    <script src="https://webapi.amap.com/maps?v=1.4.15&key=a35c7ab8cd1668ec9b9dec67402d402c"></script>
    <script src="https://a.amap.com/jsapi_demos/static/demo-center/js/demoutils.js"></script>
    <script type="text/javascript">

        var map = new AMap.Map('container', {
            resizeEnable: true, //是否监控地图容器尺寸变化
            center: [113.549843, 34.831152],
        });
        //为地图注册click事件获取鼠标点击出的经纬度坐标
        map.on('click', function (e) {
            document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat()
        });

        function setMarker(lng,lat) {
            map.clearMap();
            var marker = new AMap.Marker({
                position: [lng, lat]//位置
            })
            map.add(marker);
            map.setZoomAndCenter(16, [lng, lat]);
        }
    </script>
</body>
</html>